/**
 * 
 */
package cn.gov.msa.collection;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.gov.msa.util.PropertiesTools;
import cn.gov.msa.util.WebServiceTools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author Administrator
 *
 */
public class SharedLibraryService {

	private static String url = PropertiesTools.readProperties("share.url");
	private static String user = PropertiesTools.readProperties("share.user");
	private static String pwd = PropertiesTools.readProperties("share.pwd");
	
	public static String queryShip(JSONObject param) {
		
		JSONObject result = new JSONObject();
		int total = 0;
		JSONArray rows = new JSONArray();
		
		try{
			param.put("userName", user);
			param.put("passWord", pwd);
			
			if(!param.has("currentPage")){
				param.put("currentPage", 1);
			}
			if(!param.has("pageSize")){
				param.put("pageSize", 20);
			}
			
//			param.put("STATUS_FLAG", "1");
			
			
			String interfaceNum = PropertiesTools.readProperties("share.inter.ship");

	        String[] parameter = new String[]{interfaceNum, param.toString()};      
//			System.err.println(">>>>>>>>>" + param);        
        	JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl(url, "RService", parameter));
//			JSONObject jsonResult = JSONObject.fromObject("{\"ServiceFlag\":\"Y\",\"info\":\"查询成功\",\"datas\":{\"entry\":\"V_CB_BIG_SHIP_DATA\",\"tmp_pgCount\":{\"total\":336970,\"pages\":33697,\"currentPage\":1,\"pageSize\":10},\"rows\":[{\"SHIP_REG_NO\":\"440112000105\",\"SHIP_ID\":\"CN19954722730\",\"SHIP_FIRSTREG_NO\":\"371100402\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0762\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0762\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"-\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":0,\"SHIP_BREADTH\":0,\"SHIP_DEPTH\":0,\"SHIP_GROSSTON\":0,\"SHIP_NETTON\":0,\"SHIP_DWT\":0,\"SHIP_ENGINE_POWER\":0,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"1\",\"SHIP_CLASS_CODE\":\"-\",\"SHIP_CLASS_NAME\":\"-\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":1},{\"SHIP_REG_NO\":\"440112000110\",\"SHIP_ID\":\"CN20034302108\",\"SHIP_FIRSTREG_NO\":\"440104000082\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0866\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0866\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"B级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":43.5,\"SHIP_BREADTH\":7.2,\"SHIP_DEPTH\":2.2,\"SHIP_GROSSTON\":217,\"SHIP_NETTON\":121,\"SHIP_DWT\":180,\"SHIP_ENGINE_POWER\":198.6,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030300031\",\"SHIP_CLASS_NAME\":\"散货船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":2},{\"SHIP_REG_NO\":\"440112000112\",\"SHIP_ID\":\"CN19997164964\",\"SHIP_FIRSTREG_NO\":\"371300873\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0867\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0867\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"-\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":0,\"SHIP_BREADTH\":0,\"SHIP_DEPTH\":0,\"SHIP_GROSSTON\":0,\"SHIP_NETTON\":0,\"SHIP_DWT\":0,\"SHIP_ENGINE_POWER\":0,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"1\",\"SHIP_CLASS_CODE\":\"-\",\"SHIP_CLASS_NAME\":\"-\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":3},{\"SHIP_REG_NO\":\"440112000114\",\"SHIP_ID\":\"CN20116371828\",\"SHIP_FIRSTREG_NO\":\"440112000114\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福008\",\"SHIP_NAME_EN\":\"MIN FU 008\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"A级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"7000000\",\"SHIP_LENGTH\":86,\"SHIP_BREADTH\":16.8,\"SHIP_DEPTH\":5.2,\"SHIP_GROSSTON\":2787,\"SHIP_NETTON\":1560,\"SHIP_DWT\":3130,\"SHIP_ENGINE_POWER\":1600,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030370031\",\"SHIP_CLASS_NAME\":\"自卸砂船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":4},{\"SHIP_REG_NO\":\"440112000115\",\"SHIP_ID\":\"CN20067946778\",\"SHIP_FIRSTREG_NO\":\"440106000161\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0871\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0871\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"A级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":68,\"SHIP_BREADTH\":9.99,\"SHIP_DEPTH\":3.6,\"SHIP_GROSSTON\":772,\"SHIP_NETTON\":432,\"SHIP_DWT\":680,\"SHIP_ENGINE_POWER\":794,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030300031\",\"SHIP_CLASS_NAME\":\"散货船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":5},{\"SHIP_REG_NO\":\"440112000116\",\"SHIP_ID\":\"CN20081982171\",\"SHIP_FIRSTREG_NO\":\"440109000087\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0880\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0880\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"A级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"1000000\",\"SHIP_LENGTH\":60.5,\"SHIP_BREADTH\":9.5,\"SHIP_DEPTH\":3.45,\"SHIP_GROSSTON\":587,\"SHIP_NETTON\":328,\"SHIP_DWT\":595,\"SHIP_ENGINE_POWER\":440,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"4\",\"ALTER_FLAG\":\"1\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030370031\",\"SHIP_CLASS_NAME\":\"自卸砂船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":6},{\"SHIP_REG_NO\":\"440112000120\",\"SHIP_ID\":\"CN20031457644\",\"SHIP_FIRSTREG_NO\":\"440103000060\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0879\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0879\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"-\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"183000\",\"SHIP_LENGTH\":0,\"SHIP_BREADTH\":0,\"SHIP_DEPTH\":0,\"SHIP_GROSSTON\":0,\"SHIP_NETTON\":0,\"SHIP_DWT\":0,\"SHIP_ENGINE_POWER\":0,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"1\",\"SHIP_CLASS_CODE\":\"-\",\"SHIP_CLASS_NAME\":\"-\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":7},{\"SHIP_REG_NO\":\"440112000122\",\"SHIP_ID\":\"CN20127148504\",\"SHIP_FIRSTREG_NO\":\"440112000122\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽海巡115\",\"SHIP_NAME_EN\":\"MIN HAI XUN 115\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"B级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0905\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":0,\"SHIP_BREADTH\":2.67,\"SHIP_DEPTH\":1.14,\"SHIP_GROSSTON\":7,\"SHIP_NETTON\":2,\"SHIP_DWT\":0,\"SHIP_ENGINE_POWER\":160,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"0\",\"ALTER_FLAG\":\"1\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2070500021\",\"SHIP_CLASS_NAME\":\"巡逻船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":8},{\"SHIP_REG_NO\":\"440112000124\",\"SHIP_ID\":\"CN20082159668\",\"SHIP_FIRSTREG_NO\":\"440108000076\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0881\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0881\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"A级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"-\",\"SHIP_LENGTH\":61,\"SHIP_BREADTH\":9.5,\"SHIP_DEPTH\":3.4,\"SHIP_GROSSTON\":598,\"SHIP_NETTON\":334,\"SHIP_DWT\":550,\"SHIP_ENGINE_POWER\":440,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"4\",\"ALTER_FLAG\":\"0\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030370031\",\"SHIP_CLASS_NAME\":\"自卸砂船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":9},{\"SHIP_REG_NO\":\"440112000128\",\"SHIP_ID\":\"CN20056589616\",\"SHIP_FIRSTREG_NO\":\"440106000025\",\"SHIP_INSPECT_NO\":\"-\",\"SHIP_NAME_CN\":\"闽福州货0891\",\"SHIP_NAME_EN\":\"MIN FU ZHOU HUO 0891\",\"MMSI\":\"         \",\"SHIP_IMO\":\"-\",\"REGPORT_CODE\":\"0801\",\"REGPORT_NAME\":\"-\",\"SHIP_ROUTE_CODE\":\"1\",\"SHIP_ROUTE_NAME\":\"-\",\"SAILINGAREA_CODE\":\"-\",\"NAVIGATION_AREA_NAME\":\"A级\",\"FLAG_STATE_CODE\":\"-\",\"FLAG_STATE_NAME_CN\":\"-\",\"FLAG_STATE_NAME_EN\":\"-\",\"SHIP_TYPE_CODE\":\"0203\",\"SHIP_TYPE_NAME\":\"-\",\"SHIP_VALUE\":\"肆拾万元\",\"SHIP_LENGTH\":55.81,\"SHIP_BREADTH\":9.3,\"SHIP_DEPTH\":3.13,\"SHIP_GROSSTON\":539,\"SHIP_NETTON\":302,\"SHIP_DWT\":440,\"SHIP_ENGINE_POWER\":380,\"SHIP_PASSENGER_NUM\":0,\"MORTGAGE_FLAG\":\"0\",\"BAREBOAT_FLAG\":\"4\",\"ALTER_FLAG\":\"1\",\"HANDOUT_CARD_FLAG\":\"0\",\"FINANCIAL_LEASE_FLAG\":\"0\",\"STATUS_FLAG\":\"1\",\"TRIAL_SHIP_FLAG\":\"0\",\"HIBERNATE_FLAG\":\"0\",\"SHIP_CLASS_CODE\":\"2030370031\",\"SHIP_CLASS_NAME\":\"自卸砂船\",\"SHIP_REGION_TYPE\":\"-\",\"OWNER_NAME\":\"-\",\"MANAGER_NAME\":\"-\",\"XH\":10}]}}");

        	System.err.println(jsonResult);
        	
        	if(jsonResult.getString("ServiceFlag").equals("Y")){
				if(jsonResult.has("datas") && jsonResult.getJSONObject("datas").has("rows")){
					if(jsonResult.getJSONObject("datas").has("tmp_pgCount") && jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").has("total")){
						total = jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").getInt("total");
					}
					JSONArray ja  = jsonResult.getJSONObject("datas").getJSONArray("rows");
					for (Object object : ja) {
						JSONObject jsonShip = JSONObject.fromObject(object);
						if("1".equals(jsonShip.getString("STATUS_FLAG"))){
							
							JSONObject jsonNew = new JSONObject();
							if(jsonShip.has("SHIP_ID"))
								jsonNew.put("shipidnumber", jsonShip.getString("SHIP_ID"));					//船舶识别号
							if(jsonShip.has("SHIP_REG_NO"))
								jsonNew.put("regno", jsonShip.getString("SHIP_REG_NO"));					//船舶登记号
							if(jsonShip.has("SHIP_FIRSTREG_NO"))
								jsonNew.put("initregno", jsonShip.getString("SHIP_FIRSTREG_NO"));			//初次登记号
							if(jsonShip.has("SHIP_INSPECT_NO"))
								jsonNew.put("checkno", jsonShip.getString("SHIP_INSPECT_NO"));				//船检登记号
							if(jsonShip.has("SHIP_NAME_CN"))
								jsonNew.put("shipname", jsonShip.getString("SHIP_NAME_CN"));				//中文船名
							if(jsonShip.has("SHIP_NAME_EN"))
								jsonNew.put("shipnameen", jsonShip.getString("SHIP_NAME_EN"));				//英文船名
		//					jsonNew.put("cardno", jsonShip.getString(""));									//牌簿号
							if(jsonShip.has("SHIP_IMO"))
								jsonNew.put("imo", jsonShip.getString("SHIP_IMO"));							//IMO
							if(jsonShip.has("MMSI"))
								jsonNew.put("mmsi", jsonShip.getString("MMSI"));							//MMSI
		//					jsonNew.put("callsign", jsonShip.getString(""));								//船舶呼号
							if(jsonShip.has("REGPORT_CODE"))
								jsonNew.put("portcode", jsonShip.getString("REGPORT_CODE"));				//船籍港代码
							if(jsonShip.has("FLAG_STATE_CODE"))
								jsonNew.put("flagcode", jsonShip.getString("FLAG_STATE_CODE"));				//船旗国代码
							if(jsonShip.has("SHIP_REGION_TYPE"))
								jsonNew.put("markcode", jsonShip.getString("SHIP_REGION_TYPE"));			//海船/内河船标识代码
							if(jsonShip.has("SHIP_TYPE_CODE"))
								jsonNew.put("typecode", jsonShip.getString("SHIP_TYPE_CODE"));				//船舶种类代码
							if(jsonShip.has("SHIP_GROSSTON"))
								jsonNew.put("grosstonnage", jsonShip.getString("SHIP_GROSSTON"));			//总吨位
							if(jsonShip.has("SHIP_NETTON"))
								jsonNew.put("nettonnage", jsonShip.getString("SHIP_NETTON"));				//净吨位
							if(jsonShip.has("SHIP_DWT"))
								jsonNew.put("deadweight", jsonShip.getString("SHIP_DWT"));					//参考载重吨
							if(jsonShip.has("SHIP_ENGINE_POWER"))
								jsonNew.put("enginepower", jsonShip.getString("SHIP_ENGINE_POWER"));		//总功率
							if(jsonShip.has("SHIP_PASSENGER_NUM"))
								jsonNew.put("ratedseat", jsonShip.getString("SHIP_PASSENGER_NUM"));			//客位
							if(jsonShip.has("SHIP_LENGTH"))
								jsonNew.put("overalllength", jsonShip.getString("SHIP_LENGTH"));			//船舶总长
							if(jsonShip.has("SHIP_BREADTH"))
								jsonNew.put("mouldedbreadth", jsonShip.getString("SHIP_BREADTH"));			//船舶型宽
							if(jsonShip.has("SHIP_DEPTH"))
								jsonNew.put("mouldeddepth", jsonShip.getString("SHIP_DEPTH"));				//船舶型深
							if(jsonShip.has("SHIP_ROUTE_CODE"))
								jsonNew.put("linecode", jsonShip.getString("SHIP_ROUTE_CODE"));				//核定航线代码
							if(jsonShip.has("SAILINGAREA_CODE"))
								jsonNew.put("areacode", jsonShip.getString("SAILINGAREA_CODE"));			//核定航区代码
		//					jsonNew.put("builddate", jsonShip.getString(""));								//建造日期
							if(jsonShip.has("OWNER_NAME"))
								jsonNew.put("owner", jsonShip.getString("OWNER_NAME"));						//所有人
		//					jsonNew.put("owneraddress", jsonShip.getString(""));							//所有人地址
		//					jsonNew.put("ownertelephone", jsonShip.getString(""));							//所有人联系电话
		//							if(jsonShip.has("SHIP_ID"))
		//					jsonNew.put("ownercorporation", jsonShip.getString(""));						//所有人法人代表
							if(jsonShip.has("MANAGER_NAME"))
								jsonNew.put("operator", jsonShip.getString("MANAGER_NAME"));				//经营人
		//					jsonNew.put("operatoraddress", jsonShip.getString(""));							//经营人地址
		//					jsonNew.put("operatortelephone", jsonShip.getString(""));						//经营人联系电话
		//					jsonNew.put("operatorcorporation", jsonShip.getString(""));						//经营人法人代表
							
							rows.add(jsonNew);
						}
					}
				}
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		result.put("total", total);
		result.put("rows", rows);
			
		return result.toString();
	}
	
	public static String check(JSONObject param){
		JSONArray result = new JSONArray();
		JSONObject data = new JSONObject();
		String value;
		if(param.has("SHIP_REG_NO")){
			value = "{\"SHIP_REG_NO\":\""+param.get("SHIP_REG_NO")+"\"}";
			data=queryCountry(JSONObject.fromObject(value));  //国籍证书校验信息
			data.put("shipidnumber", param.getString("SHIP_ID"));
			result.add(data);
			data = queryOwnerShip(JSONObject.fromObject(value));  //所有权
			data.put("shipidnumber", param.getString("SHIP_ID"));
			result.add(data);
		}
		if(param.has("SHIP_ID")){
			value = "{\"SHIP_ID\":\""+param.get("SHIP_ID")+"\"}";
			data = queryShipInspect(JSONObject.fromObject(value));  //船检证书
			JSONArray arr = data.getJSONArray("data");
			for(Object object : arr){
			JSONObject json = JSONObject.fromObject(object);
			json.put("shipidnumber", param.getString("SHIP_ID"));
			result.add(json);
			}
		}
		if(param.has("SHIP_NO")){
			value = "{\"SHIP_NO\":\""+param.get("SHIP_NO")+"\"}";
			data = queryShipFSC(JSONObject.fromObject(value));   //fsc
			data.put("shipidnumber", param.getString("SHIP_ID"));
			result.add(data);
		}
		return result.toString();
	}
	
	
	public static JSONObject queryCountry(JSONObject param) {

		JSONObject result = new JSONObject();
		int total = 0;
		String check = "持有有效的《船舶国籍证书》";
		String info = "无有效的国籍证书";
		int flag = 0; // 校验不通过
		try {
			param.put("userName", user);
			param.put("passWord", pwd);

			if (!param.has("currentPage")) {
				param.put("currentPage", 1);
			}
			if (!param.has("pageSize")) {
				param.put("pageSize", 20);
			}

			String interfaceNum = PropertiesTools.readProperties("share.inter.country");

			String[] parameter = new String[] { interfaceNum, param.toString() };
			JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl(url, "RService", parameter));
			if (jsonResult.getString("ServiceFlag").equals("Y") && jsonResult.has("datas")) {
				total = jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").getInt("total");
				JSONArray ja = jsonResult.getJSONObject("datas").getJSONArray("rows");
				if (total > 0) { // 有记录
					Date now = new Date();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					for (Object object : ja) { // 防止共享库返回多余的过期证书
						JSONObject jsonCountry = JSONObject.fromObject(object);
						if (jsonCountry.has("EXPIRE_DATE")) {
							if (!now.after(sdf.parse(jsonCountry.getString("EXPIRE_DATE")))) {
								info = "持有该证书，有效期截止：" + jsonCountry.getString("EXPIRE_DATE").substring(0, 10)+"，证书有效";
								flag = 1;
								break;
							} else {
								info = "持有该证书，有效期截止：" + jsonCountry.getString("EXPIRE_DATE").substring(0, 10)+"，证书已过期";
								flag = -1;
							}
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			info = "校验出错";
		} finally {
			result.put("verifyresultcode", flag);
			result.put("verifyresultdesc", info);
			result.put("verifyname", check);
			result.put("verifytypecode", "0101");
			result.put("verifytime", new Date());
		}

		return result;

	}
	
	public static JSONObject queryOwnerShip(JSONObject param) { // 所有权信息

		JSONObject result = new JSONObject();
		int total = 0;
		String check = "持有效的《船舶所有权登记证书》";
		String info = "无有效的船舶所有权登记信息";
		int flag = 0; // 校验不通过
		try {
			param.put("userName", user);
			param.put("passWord", pwd);

			if (!param.has("currentPage")) {
				param.put("currentPage", 1);
			}
			if (!param.has("pageSize")) {
				param.put("pageSize", 20);
			}

			String interfaceNum = PropertiesTools.readProperties("share.inter.ownership");

			String[] parameter = new String[] { interfaceNum, param.toString() };

			JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl(url, "RService", parameter));
			if (jsonResult.getString("ServiceFlag").equals("Y") && jsonResult.has("datas")) {
				total = jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").getInt("total");
				JSONArray ja = jsonResult.getJSONObject("datas").getJSONArray("rows");
				if (total > 0) { // 有记录
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					JSONObject object = ja.getJSONObject(0);
					JSONObject jsonOwnerShip = JSONObject.fromObject(object);
					if (jsonOwnerShip.has("CERT_OBTAIN_DATE")) {
						info = "船舶所有权取得日期：" + jsonOwnerShip.getString("CERT_OBTAIN_DATE").substring(0, 10);
						flag = 1;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			info = "校验出错";
		} finally {
			result.put("verifyresultcode", flag);
			result.put("verifyresultdesc", info);
			result.put("verifyname", check);
			result.put("verifytypecode", "0102");
			result.put("verifytime", new Date());
		}

		return result;

	}
	
	@SuppressWarnings("static-access")
	public static JSONObject queryShipInspect(JSONObject param) {   //船检证书信息
		JSONObject result = new JSONObject();
		JSONArray rows = new JSONArray();
		int total = 0;
		String info = "无有效的船检证书";
		String check ="持有有效的船舶检验证书";
		int flag = 0; // 校验不通过
		JSONObject json = new JSONObject();
		try {
			param.put("userName", user);
			param.put("passWord", pwd);

			if (!param.has("currentPage")) {
				param.put("currentPage", 1);
			}
			if (!param.has("pageSize")) {
				param.put("pageSize", 20);
			}

			String interfaceNum = PropertiesTools.readProperties("share.inter.shipinspect");

			String[] parameter = new String[] { interfaceNum, param.toString() };
			JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl(url, "RService", parameter));
			if (jsonResult.getString("ServiceFlag").equals("Y") && jsonResult.has("datas")) {
				total = jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").getInt("total");
				JSONArray ja = jsonResult.getJSONObject("datas").getJSONArray("rows");
				if (total > 0) { // 有记录
					Date now = new Date();
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
					for (Object object : ja) { 
						JSONObject jsonInspect = JSONObject.fromObject(object);
						if ("-".equals(jsonInspect.getString("CERT_DUEDATE"))){
						   check = "持有效的《"+jsonInspect.get("CERT_NAME")+"》";
						   info = "持有该证书，证书有效";
						   flag = 1;
						}else{
							if (!now.after(sdf.parse(jsonInspect.getString("CERT_DUEDATE")))) {
								check = "持有效的《"+jsonInspect.get("CERT_NAME")+"》";
								info = "持有该证书，有效期止："+jsonInspect.getString("CERT_DUEDATE").substring(0, 10)+"，证书有效";
								flag = 1;
							}else{
								check = "持有效的《"+jsonInspect.get("CERT_NAME")+"》";
								info = "持有该证书,有效期止："+jsonInspect.getString("CERT_DUEDATE").substring(0, 10)+"，证书已失效";
								flag = -1;
							}
						}
						json.put("verifyresultcode", flag);
						json.put("verifyname", check);
						json.put("verifyresultdesc", info);
						json.put("verifytypecode", "0104");
						json.put("verifytime", new Date());
						rows.add(json);
						json.clear();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			info = "校验出错";
		} finally {
			result.put("data", rows.toString());
			
		}
		return result;

	}
	
	public static JSONObject queryShipFSC(JSONObject param) { // FSC信息

		JSONObject result = new JSONObject();
		int total = 0;
		String check = "安检时限的规定是否符合";
		String info = "无最近的安检信息";
		int flag = 0; // 校验不通过
		try {
			param.put("userName", user);
			param.put("passWord", pwd);

			if (!param.has("currentPage")) {
				param.put("currentPage", 1);
			}
			if (!param.has("pageSize")) {
				param.put("pageSize", 20);
			}

			String interfaceNum = PropertiesTools.readProperties("share.inter.shipfsc");

			String[] parameter = new String[] { interfaceNum, param.toString() };

			JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl(url, "RService", parameter));
			if (jsonResult.getString("ServiceFlag").equals("Y") && jsonResult.has("datas")) {
				total = jsonResult.getJSONObject("datas").getJSONObject("tmp_pgCount").getInt("total");
				JSONArray ja = jsonResult.getJSONObject("datas").getJSONArray("rows");
				if (total > 0) { // 有记录
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					JSONObject object = ja.getJSONObject(0);
					JSONObject jsonShipFsc = JSONObject.fromObject(object);
					if (jsonShipFsc.has("INSPECT_DATE")) {
						String fromDate = sdf.format(new Date());
						String toDate = sdf.format(jsonShipFsc.getString("INSPECT_DATE"));
						long from = sdf.parse(fromDate).getTime();
						long to = sdf.parse(toDate).getTime();
						int days = (int) ((to - from)/(1000 * 60 * 60 * 24));
						if(days > 180){
						info = "最近一次于"+jsonShipFsc.getString("INSPECT_DATE").substring(0, 10)+"日的安检，距现已超过6个月，安检信息已过期";
						flag = 0;
						}else{
						info = "最近一次于"+jsonShipFsc.getString("INSPECT_DATE").substring(0, 10)+"日的安检，距现不足6个月，未达到安检时限";
						flag = 1;
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			info = "校验出错";
		} finally {
			result.put("verifyresultcode", flag);
			result.put("verifyresultdesc", info);
			result.put("verifyname", check);
			result.put("verifytypecode", "0105");
			result.put("verifytime", new Date());
		}

		return result;

	}
	
	
//	"{\"SLJGDM\":\"060010\"}"
	public static String queryBerth(JSONObject param) {
		
		JSONObject result = new JSONObject();
		int total = 0;
		JSONArray rows = new JSONArray();
		
		try{
			String interfaceNum = "FS002";

	        String[] parameter = new String[]{interfaceNum, param.toString()};      
	        JSONObject jsonResult = JSONObject.fromObject(WebServiceTools.getDatasByUrl("http://198.32.70.2:8011/shipvisaproj/proxy/DataCenterServices_PS?WSDL", "getData", parameter));

			if(jsonResult.getString("result").equals("1")){
				total = jsonResult.getJSONObject("datas").getJSONObject("table").getJSONArray("row").size();
				JSONArray ja  = jsonResult.getJSONObject("datas").getJSONObject("table").getJSONArray("row");
				for (Object object : ja) {
					JSONObject jsonShip = JSONObject.fromObject(object);
					
					JSONObject jsonNew = new JSONObject();
					if(jsonShip.has("BWBH"))
						jsonNew.put("berthcode", jsonShip.getString("BWBH"));					//泊位代码
					if(jsonShip.has("BWMC"))
						jsonNew.put("berth", jsonShip.getString("BWMC"));					//泊位名称
					
					rows.add(jsonNew);

				}
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		result.put("total", total);
		result.put("rows", rows);
			
		return result.toString();
	}
	
	

	

	public static void main(String[] args) {
		
				
//		String url = PropertiesTools.readProperties("data.url");
//		System.out.println(url);
//
//        String[] parameter = new String[]{"FS002", "{\"SLJGDM\":\"060000\"}"};  
//		
//        try {
//        	System.out.println(">>>>>111");
//			String ss = WebServiceTools.getDatasByUrl(url, "getData", parameter);
//
//        	System.out.println(">>>>>222");
//			System.out.println(ss);
//			
//		} catch (DocumentException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (XmlPullParserException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
	}
}
